﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using QuanLyThuVien1.DTO;
using QuanLyThuVien1.BUS;
using QuanLyThuVien1.DAO;

namespace QuanLyThuVien1.GUI
{
    public partial class Fr_HieuChinhTTCaNhan : Form
    {
        public Fr_HieuChinhTTCaNhan()
        {
            InitializeComponent();
        }
        public string ChuanHoa(string m_sChuoi)
        {
            if (m_sChuoi == "")
                return m_sChuoi;
            for (int i = 0; i < m_sChuoi.Length - 1; )
            {
                if (m_sChuoi[i] == 32 && m_sChuoi[i + 1] == 32)
                {
                    m_sChuoi = m_sChuoi.Substring(0, i + 1) + m_sChuoi.Substring(i + 2, m_sChuoi.Length - i - 2);
                }
                else
                    i++;
            }
            if (m_sChuoi[0] == 32 && m_sChuoi.Length == 1)
                return "";

            if (m_sChuoi[0] == 32)
                m_sChuoi = m_sChuoi.Substring(1, m_sChuoi.Length - 1);
            if (m_sChuoi[m_sChuoi.Length - 1] == 32)
                m_sChuoi = m_sChuoi.Substring(0, m_sChuoi.Length - 1);
            return m_sChuoi;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                DOCGIA d = new DOCGIA();
                CDocGia_Bus d1 = new CDocGia_Bus();
                string pass = textBox2.Text; 
                string tenTaiKhoan = tbTaiKhoan.Text;
                d.PASSW = textBox3.Text;
                d.EMAIL = textBox7.Text;
                d.DIENTHOAI = textBox4.Text;
                d.DIACHI = textBox5.Text;
                if (ChuanHoa(textBox3.Text) == "")
                {
                    MessageBox.Show("PassWord Phải chứa Kí Tự", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    d1.CapNhatThongTinDG1(d, tenTaiKhoan, pass);
                    MessageBox.Show("Đã câp Nhật Thông tin Xong", "Thông Báo");
                }
            }
            catch (System.Exception n)
            {
                MessageBox.Show(n.Message);
            }
            
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            if (ChuanHoa(textBox3.Text) == "")
            {
                MessageBox.Show("PassWord Phải chứa Kí Tự", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}